home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / hypercar / mactool / delimfix.cpt / The Delimiter Fixer 1.0.3 / stack_-1.xml < prev    next >
Encoding:
Extensible Markup Language  |  1991-10-30  |  17.3 KB  |  23 lines

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE stack PUBLIC "-//Apple, Inc.//DTD stack V 2.0//EN" "" >
  3. <stack>
  4.     <name>in.3</name>
  5.     <id>-1</id>
  6.     <cardCount>3</cardCount>
  7.     <cardID>2959</cardID>
  8.     <listID>4019</listID>
  9.     <cantModify><false /></cantModify>
  10.     <cantDelete><false /></cantDelete>
  11.     <cantAbort><false /></cantAbort>
  12.     <cardSize>
  13.         <width>256</width>
  14.         <height>288</height>
  15.     </cardSize>
  16.     <script>Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧Γê₧
  17. THE DELIMITER FIXER
  18. ┬⌐1991 Geoff Duncan, Red Split Ends Inc.
  19. This stack is free, although the author maintains copyright.  You may
  20. not sell this stack or charge for its distribution without the express permission
  21. of the author AND the author(s) of materials contained herein.
  22.  
  23. XFCNs used in this stack:
  24. HierPopUpMenus, ┬⌐ Jon Pugh  jpugh@apple.com
  25. XCMDs used in this stack:
  26. HCBalloon, ┬⌐ Len Saaf  saaf@joker.optics.rochester.edu
  27. Used within limits specified by the authors.
  28. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  29. on openstack
  30. if the version < 2.1 then
  31. answer the short name of this stack && "requires HyperCard 2.1 or higher." && ┬¼
  32. "Many features of this stack will not work properly with an earlier version of HyperCard."┬¼
  33. & return & "See the Stack OverView for more information."
  34. end if
  35. put "<<none>>" into bg fld "Import"
  36. put "<<none>>" into bg fld "Export"
  37. -- put empty into bg fld "Specified Header"
  38. dfremovemask
  39. hide bg btn id 32 --ok
  40. hide bg btn id 46 --save
  41. hide bg fld "Specified Header"
  42. DFSetUpMenu On
  43. pass openstack --for others
  44. end openstack
  45.  
  46. on closestack
  47. global DFImportFile, DFExportFile,FieldDelimiter,RecordDelimiter
  48. put empty into DFImportFile
  49. put empty into DFExportFile
  50. put empty into FieldDelimiter
  51. put empty into RecordDelimiter
  52. if the freesize of this stack > .1 * the size of this stack then
  53. put the freesize of this stack div 1024 & "K free in stack" && the short name┬¼
  54. of this stack & ". Compacting..."
  55. domenu "Compact Stack"
  56. hide msg
  57. end if
  58. DFSetUpMenu Off
  59. pass closestack --ferothers
  60. end closestack
  61.  
  62. on suspendStack
  63. DFSetUpMenu Off
  64. pass suspendstack --for others, if any
  65. end suspendstack
  66.  
  67. on resumeStack
  68. DFSetUpMenu On
  69. send "opencard" to this card
  70. pass resumeStack --for others, if any
  71. end resumeStack
  72.  
  73. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  74. MAIN CARD HANDLERS
  75. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  76.  
  77. --asks for and obtains paths for import and export files
  78. on DFgetAFile which
  79. global DFImportFile, DFExportFile
  80. if which is "Import" then
  81. answer file "Please name an" && which && "file:" of type TEXT
  82. else
  83. ask file "Please name an" && which && "file:"
  84. end if
  85. if (it is not empty) or (the result is not "Cancel") then
  86. put FileFromPath(it) into bg fld which
  87. if which is "import" then put it into DFImportFile
  88. else put it into DFExportFile
  89. else put "<<none>>" into bg fld which
  90. end DFgetAFile
  91. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  92. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  93. on GODelimiterFixer
  94. --
  95. GetUserSettings -- gets user settings
  96. if the result is empty then exit GODelimiterFixer
  97. --
  98. GetProperHeader
  99. put the result into DFHeader
  100. if DFHeader is empty then exit GODelimiterFixer
  101. ParseTheHeader DFHeader
  102. put the result into DFHeader
  103. if DFHeader is empty then exit GODelimiterFixer
  104. --
  105. if the hilite of bg btn "Variable to fixed" then VarToFixed DFHeader
  106. else FixedToVar DFHeader
  107. --
  108. play finis f c g cw
  109. end GODelimiterFixer
  110.  
  111. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  112. on GetUserSettings
  113. global DFImportFile, DFExportFile,FieldDelimiter, RecordDelimiter
  114. if (bg fld "Import" is empty) or (bg fld "import" is "<<none>>") then
  115. beep
  116. answer "No import file specified." with "OK"
  117. return empty -- puts empty into "the result" for later processing
  118. end if
  119. if (bg fld "Export" is empty) or (bg fld "Export" is "<<none>>") then
  120. beep
  121. answer "No export file specified." with "OK"
  122. return empty -- puts empty into "the result" for later processing
  123. end if
  124. if DFImportFile is DFExportFile then
  125. beep
  126. answer "Import and Export files may not be identical." with "Oh hell."
  127. put "<<none>>" into bg fld Import
  128. put "<<none>>" into bg fld Export
  129. return empty
  130. end if
  131. --now obtains user settings and puts them into the appropriate global variables
  132. -- used in the routines.  Also puts the appropriate character values in where needed.
  133. put the short name of bg btn id 5 into FieldDelimiter
  134. put the short name of bg btn id 15 into RecordDelimiter
  135. if fieldDelimiter is RecordDelimiter then
  136. beep
  137. answer "Field and Record delimiters may not be identical." with "Oh hell."
  138. return empty
  139. end if
  140. --those are the "popup" buttons
  141. if  (FieldDelimiter is "Colon")┬¼
  142. or (FieldDelimiter is "Tab")┬¼
  143. or (FieldDelimiter is "Comma")┬¼
  144. or (FieldDelimiter is "Space") then
  145. put value(FieldDelimiter) into FieldDelimiter
  146. else
  147. if (FieldDelimiter is "SemiColon") then put ";" into FieldDelimiter
  148. end if
  149. if  (RecordDelimiter is "Return")┬¼
  150. or (RecordDelimiter is "Tab")┬¼
  151. or (RecordDelimiter is "Space") then
  152. put value(RecordDelimiter) into RecordDelimiter
  153. end if
  154. --
  155. return true
  156. end GetUserSettings
  157.  
  158. on GetProperHeader
  159. --returns the appropriate header for operation...  returns EMPTY if none
  160. global RecordDelimiter, DFImportFile
  161. put empty into WhichHeader
  162. open file DFImportFile
  163. read from file DFImportFile until RecordDelimiter --gets header information if present
  164. put it into FirstLine
  165. close file DFImportFile
  166. put bg fld "Specified Header" into SpecHeader
  167. --here's the testing section
  168. if isValidHeader(FirstLine) and isValidHeader(SpecHeader) then
  169. --BOTH ARE VALID
  170. answer "The file" && quote & FileFromPath(DFImportFile) & quote &&┬¼
  171. "apparently contains valid header information." && ┬¼
  172. "Do you wish to use this information or the header you supplied?" ┬¼
  173. with "FileΓÇÖs" or  "Mine" or "Cancel"
  174. if it is "Cancel" then return empty
  175. put it into whichHeader
  176. end if
  177. if isValidHeader(SpecHeader) and ┬¼
  178. ((whichHeader is empty) or (whichHeader is "Mine")) then return SpecHeader
  179. --SPECHEADER VALID
  180. if isValidHeader(firstLine) and ┬¼
  181. ((WhichHeader is empty) or (WhichHeader is "FileΓÇÖs")) then return FirstLine
  182. --FIRSTLINE VALID
  183. if not(isValidHeader(firstLine)) and not(isValidHeader(SpecHeader)) then
  184. --BOTH ARE INVALID
  185. answer "Neither the file" && quote & FileFromPath(DFImportFile) & quote &&┬¼
  186. "nor this stack contain a valid Header.  Please see this stackΓÇÖs documentation" &&┬¼
  187. "for information about creating a Header." with "OK"
  188. return empty
  189. end if
  190. end GetProperHeader
  191.  
  192. on ParseTheHeader Header
  193. --this leaves us with a return-separated list
  194. global fieldDelimiter
  195. if not(isValidHeader(header)) then return empty
  196. if header contains fieldDelimiter then put FieldDelimiter into Delim
  197. else put comma into Delim
  198. if not(header contains Delim) then
  199. answer "The specfied Header is not valid.  Please see this stackΓÇÖs documentation" &&┬¼
  200. "for information on creating a valid Header." with "OK"
  201. return empty
  202. end if
  203. put StripReturnsAndSpaces(header) into header
  204. delete char 1 to 2 of header --removes <<
  205. put the number of chars in header into lastChar
  206. delete char lastchar -1 to lastchar of header --removes >>
  207. --this removes all FIELDDELIMITERS so we can parse out column notations
  208. repeat with i = 1 to the number of chars in header
  209. if char i of header is Delim then put return into char i of header
  210. end repeat
  211. return Header
  212. end ParseTheHeader
  213.  
  214. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  215.  
  216. on VarToFixed Columns
  217. global DFImportFile, DFExportFile, FieldDelimiter, RecordDelimiter, DFDATA
  218. if columns is "PreWarm" then exit VarToFixed
  219. disallowinterruption
  220. DFSetUpMask
  221. open file DFImportFile
  222. open file DFExportFile
  223. if not(the hilite of bg btn "Low Memory Mode") then LoadAllData DFImportFile --Γêå
  224. put 0 into processedRecords
  225. set the itemdelimiter to FieldDelimiter
  226. repeat -- until eof
  227. if UserInterrupt() then exit repeat
  228. -- read from file DFImportFile until RecordDelimiter -- one "line"
  229. get theNextRecord()
  230. if it is empty then exit repeat
  231. put it into Field
  232. -- delete the last char of Field -- the record delimiter
  233. put empty into FixedFields
  234. repeat with i = 1 to the number of lines in Columns
  235. set cursor to busy
  236. ConvertToFixedField item i of Field, line i of columns
  237. put the result after FixedFields
  238. end repeat
  239. write FixedFields & return to file DFExportFile
  240. put ProcessedRecords + 1 into ProcessedRecords
  241. DFMaskMessage "Records Processed:" && ProcessedRecords & return & ┬¼
  242. "Hold down ∩ú┐-option-mouse to interrupt."
  243. end repeat
  244. CleanUpStuff
  245. end VarToFixed
  246.  
  247. on ConvertToFixedField field, columns
  248. put the number of chars in field into FieldChars
  249. if FieldChars > columns then
  250. delete char columns + 1 to (fieldchars) of field
  251. return field
  252. else
  253. repeat columns - fieldchars times
  254. put space after field
  255. end repeat
  256. return field
  257. end if
  258. end ConvertToFixedField
  259.  
  260. on FixedToVar Columns
  261. --converts fixed-field format to variable-length
  262. global DFImportFile, DFExportFile, FieldDelimiter, RecordDelimiter, DFDATA
  263. if columns is "PreWarm" then exit FixedToVar
  264. disallowinterruption
  265. DFSetUpMask
  266. open file DFImportFile
  267. open file DFExportFile
  268. if not(the hilite of bg btn "Low Memory Mode") then LoadAllData DFImportFile --Γêå
  269. put 0 into processedRecords
  270. repeat
  271. if UserInterrupt() then exit repeat
  272. -- read from file DFImportFile until return --gets one line
  273. get theNextRecord()
  274. if it is empty then exit repeat
  275. put it into Record
  276. put 1 into FirstChar
  277. repeat with i = 1 to the number of lines in columns
  278. set the cursor to busy
  279. put stripReturnsAndSpaces(char FirstChar to (firstChar +line i of Columns -1)┬¼
  280. of Record) after VarRecord
  281. put varRecord & FieldDelimiter into VarRecord
  282. put firstChar + line i of Columns into firstChar
  283. end repeat
  284. put recordDelimiter into the last char of VarRecord
  285. write VarRecord to file DFExportFile
  286. put empty into VarRecord
  287. put ProcessedRecords + 1 into ProcessedRecords
  288. DFMaskMessage "Records Processed:" && ProcessedRecords & return & ┬¼
  289. "Hold down ∩ú┐-option-mouse to interrupt."
  290. end repeat
  291. CleanUpStuff
  292. end FixedToVar
  293.  
  294. on LoadAllData infile
  295. --loads all data into a single global variable for faster processing
  296. answer "Hypercard has approximately" && the heapspace div 1024 & "K"┬¼
  297. && "of free in which to process your data.  If this figure isnΓÇÖt larger"┬¼
  298. && "than your input file, please choose ΓÇ£AbortΓÇ¥ and either allocate"┬¼
  299. && "more memory to HyperCard or run The Delimiter Fixer in Low Memory Mode."┬¼
  300. with "Continue" or "Abort"
  301. if it is "abort" then
  302. global DFImportFile
  303. close file DFImportFile
  304. return empty
  305. end if
  306. global DFDATA
  307. read from file infile until end --eof
  308. if the result contains "not enough memory" then
  309. answer "Sorry, there is not enough memory to load your data file."┬¼
  310. && "Either attempt this operation in Low Memory Mode or"┬¼
  311. && "split your data file into smaller segments." with "OK"
  312. return empty
  313. end if
  314. put it into DFDATA
  315. close file infile
  316. end LoadAllData
  317.  
  318. on CleanUpStuff
  319. --cleans up after conversion procedures
  320. global DFDATA, DFImportFile, DFExportFile
  321. if the hilite of bg btn "Low Memory Mode" then close file DFImportFile
  322. close file DFExportFile
  323. put empty into DFDATA
  324. DFRemoveMask
  325. allowinterruption
  326. end CleanUpStuff
  327.  
  328. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  329. MASK ROUTINES
  330. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  331.  
  332. on DFSetUpMask
  333. --sets up the mask field for user messages etc. during conversion run
  334. lock screen
  335. show bg fld mask
  336. put empty into bg fld mask
  337. repeat 6 times -- the number of visible lines
  338. put return after bg fld mask
  339. end repeat
  340. unlock screen with dissolve very fast
  341. end DFSetUpMask
  342.  
  343. on DFRemoveMask
  344. --removes mask and clears out its field
  345. lock screen
  346. put empty into bg fld mask
  347. hide bg fld mask
  348. hide bg btn "OK"
  349. hide bg btn "Save..."
  350. unlock screen with dissolve very fast
  351. end DFRemoveMask
  352.  
  353. on DFMaskMessage TheMess
  354. --puts THEMESS as a message to user during conversion at bottom of mask field
  355. put theMess into line (5 - the number of lines in themess) to 5 of bg fld mask
  356. -- 5 is the last visible line
  357. end DFMaskMessage
  358.  
  359. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  360. MENU ROUTINES
  361. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  362. on DFSetUpMenu which
  363. show menubar
  364. if which is "on" then
  365. if there is not a menu "DF" then
  366. create menu "DF"
  367. put "Main Card,DF Help,DF Headers" into menu "DF"
  368. set the menuMessage of menuitem "Main Card" of menu "DF" to DFMainCard
  369. set the menuMessage of menuitem "DF Help" of menu "DF" to DFHelp
  370. set the menuMessage of menuitem "DF Headers" of menu "DF" to DFHeaders
  371. end if
  372. else if which is "off" then
  373. reset menubar
  374. end if
  375. end DFSetUpMenu
  376.  
  377. on DFMainCard
  378. lock screen
  379. go to card "Main Card"
  380. unlock screen with dissolve
  381. end DFMainCard
  382.  
  383. on DFHelp
  384. lock screen
  385. go to card "DF Help"
  386. unlock screen with wipe right fast
  387. end DFHelp
  388.  
  389. on DFHeaders
  390. lock screen
  391. go to card "DF Headers"
  392. unlock screen with wipe right fast
  393. end DFheaders
  394.  
  395. ∞∞∞∞∞∞∞∞FUNCTIONS∞∞∞∞∞∞∞∞∞∞∞∞∞
  396. function SomeOtherDelimiter
  397. ask "Please enter the delimiter of your choice:"
  398. if (it is empty) or (it is "Cancel") then return empty
  399. return it
  400. end SomeOtherDelimiter
  401.  
  402. Function printField
  403. -- accumulates the text of the documentation together into one (big!) string for printing
  404. -- purposes.
  405. put "Intro" & return & "About" & return & "Operation" & return &┬¼
  406. "Info #1" & return & "Info #2" into TheFields
  407. repeat with i = 1 to the number of lines in TheFields
  408. put bg fld line i of TheFields & return & return & return after manual
  409. end repeat
  410. return manual
  411. end printField
  412.  
  413. function FileFromPath path
  414. --requires hyperCard 2.1 or higher due to the use of THE ITEMDELIMITER.
  415. --returns the last item of a pathname, most probably a file
  416. set the itemdelimiter to colon
  417. return the last item of path
  418. end FileFromPath
  419.  
  420. function IsValidHeader TheText
  421. --tests to see if the text supplied meets minimal criteria as a valid header...
  422. put stripReturnsAndSpaces(theText) into TheText
  423. put the number of chars in TheText into LastChar
  424. if (char 1 to 2 of TheText is "<<") then
  425. if char lastChar-1 to lastChar of TheText is ">>" then return true
  426. end if
  427. return false
  428. end IsValidHeader
  429.  
  430. function theNextRecord
  431. global RecordDelimiter
  432. --loads the next "record" to be processed, whether from disk or memory.  It
  433. --deletes each "record" from the global variable as it it processed.
  434. if the hilite of bg btn "Low Memory Mode" then
  435. global DFImportFile
  436. read from file DFImportFile until RecordDelimiter -- one "line"
  437. delete the last char of it --removes the record delimiter
  438. return it
  439. else
  440. global DFDATA, RecordDelimiter
  441. put the itemdelimiter into savedDelimiter
  442. set the itemdelimiter to RecordDelimiter
  443. get the first item of DFDATA
  444. delete the first item of DFDATA
  445. set the itemdelimiter to savedDelimiter
  446. return it
  447. end if
  448. end theNextRecord
  449.  
  450. function UserInterrupt
  451. --optional interrupt
  452. if the commandkey is down then
  453. if (the optionkey is down) and (the mouse is down) then
  454. beep 3
  455. return true
  456. end if
  457. end if
  458. return false
  459. end UserInterrupt
  460.  
  461. function stripReturnsAndSpaces theText
  462. --this is stolen from some Claris stack (I don't remember which) and is somewhat
  463. --modified to strip spaces from the front of a string and both spaces and returns from the
  464. --end. I think the original just removed things from the end
  465. repeat
  466. if (the last char of theText is space) or (the last char of theText is return)┬¼
  467. then delete the last char of theText
  468. else
  469. if (the first char of theText is space) then delete the first char of theText
  470. else return theText
  471. end if
  472. end repeat
  473. end stripReturnsAndSpaces
  474.  
  475. function HitTest where, what
  476. --stolen from Jon Pugh's HPopUpMenu stack for the little arrow icons
  477. --on the ends of popup menus
  478. if what = "" or what = "btn" then
  479. repeat with i = the number of cd btns down to 1
  480. if where is within rect of cd btn i then
  481. if visible of cd btn i and name of cd btn i Γëá name of target
  482. then return "cd btn id " & the id of cd btn i
  483. end if
  484. end repeat
  485. repeat with i = the number of bg btns down to 1
  486. if where is within rect of bg btn i then
  487. if visible of bg btn i and name of bg btn i Γëá name of target
  488. then return " bg btn id "& the id of bg btn i
  489. end if
  490. end repeat
  491. end if
  492. if what = "" or what = "fld" then
  493. repeat with i = the number of cd flds down to 1
  494. if where is within rect of cd fld i then
  495. if visible of cd fld i and name of cd fld i Γëá name of target
  496. then return "cd fld id " & the id of cd fld i
  497. end if
  498. end repeat
  499. repeat with i = the number of bg flds down to 1
  500. if where is within rect of bg fld i then
  501. if visible of bg fld i and name of bg fld i Γëá name of target
  502. then return " bg fld id "& the id of bg fld i
  503. end if
  504. end repeat
  505. end if
  506. return ""
  507. end HitTest</script>
  508.     <background id="2681" file="background_2681.xml" name="" />
  509.     <background id="4711" file="background_4711.xml" name="" />
  510.     <card id="2959" file="card_2959.xml" marked="false" name="Main Card" owner="2681" />
  511.     <card id="4900" file="card_4900.xml" marked="false" name="DF Help" owner="4711" />
  512.     <card id="4565" file="card_4565.xml" marked="false" name="DF Headers" owner="4711" />
  513. </stack>
  514.